package com.xtayfjpk.zookeeper.test.master_workers.callback.worker;

import org.apache.log4j.Logger;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;

import com.xtayfjpk.zookeeper.test.master_workers.Worker;
import com.xtayfjpk.zookeeper.test.master_workers.callback.BaseStringCallback;

public class WorkerTaskStatusCreateCallback extends BaseStringCallback {
	private static final Logger LOGGER = Logger.getLogger(WorkerTaskStatusCreateCallback.class);
	private Worker worker;
	
	public WorkerTaskStatusCreateCallback(Worker worker) {
		this.worker = worker;
	}
	
	@Override
	protected void connectionLossCaseAction(int rc, String path, Object ctx, String name) {
		worker.createDoneStatus(path);
	}
	
	@Override
	protected void okCaseAction(int rc, String path, Object ctx, String name) {
		LOGGER.info("Created status znode correctly: " + name);
	}
	
	@Override
	protected void nodeExistsCaseAction(int rc, String path, Object ctx, String name) {
		LOGGER.warn("Node exists: " + path);
	}
	
	@Override
	protected void defaultCaseAction(int rc, String path, Object ctx, String name) {
		LOGGER.error("Failed to create task data: ", KeeperException.create(Code.get(rc), path));
	}
}
